

package com.central.apps.dao;

import com.central.apps.entity.BizFlowConsult;
import com.central.apps.entity.BizFlowConsultDtl;
import com.central.apps.entity.BizFlowCountersign;
import com.central.bizcommon.model.system.SysDept;

import java.util.List;
import java.util.Map;

import com.central.common.model.SysUser;
import org.apache.ibatis.annotations.*;

@Mapper
public interface BizCustomDao {

    @Select({"select * from bl_appversion where type=#{type} order by versionnum desc limit 1"})
    Map<String, Object> findMaxVersion(String var1);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into sys_user(username, password, nickname, headimgurl, worknumber, idnumber, phone, sex, enabled, type, email, address, birthday, zipcode, telephone, companyid,entrytime, education, post, tips, createtime, updatetime, createuser, updateuser, version, ispermit, ipaddress, macaddress, synchrotime, islogin, user_type, user_active_date, taskdeputy, taskdeputydesc, deputytime, firstlogin, leaveoffice, labarcode, erp, del_flag,deptcode,weiinfo) "
            + "values(#{username}, #{password}, #{nickname}, #{headimgurl}, #{worknumber}, #{idnumber}, #{phone}, #{sex}, #{enabled}, #{type}, #{email},  #{address}, #{birthday}, #{zipcode}, #{telephone}, #{companyid},#{entrytime}, #{education}, #{post}, #{tips}, #{createtime}, #{updatetime}, #{createuser}, #{updateuser}, #{version}, #{ispermit}, #{ipaddress}, #{macaddress}, #{synchrotime},#{islogin},#{user_type},#{user_active_date}, #{taskdeputy}, #{taskdeputydesc}, #{deputytime}, 1, 0, #{labarcode}, #{erp},'0',#{deptcode},#{weiinfo})")
    int userSave(SysUser sysUser);

    @Select("select t.id,t.username from sys_user t where binary t.username = #{username}")
    Map<String,Object> findByUsername(String username);

    @Select("select id, username, nickname, headimgurl, worknumber, idnumber, phone, sex, enabled, type, email, address, birthday, zipcode, telephone, companyid,entrytime, education, post, tips, createtime, updatetime, createuser, updateuser, version, ispermit, ipaddress, macaddress, synchrotime, islogin, user_type, user_active_date, taskdeputy, taskdeputydesc, deputytime, firstlogin, leaveoffice, labarcode, erp, del_flag,t.deptcode,t.weiinfo,t.sourceid,t.sourcedesc from sys_user t where t.del_flag='0' and t.worknumber = #{worknumber}")
    Map<String, Object> findMapByWorknumber(String worknumber);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert({"insert into sys_dept(pid, `code`,pcode, simplename, fullname, type, sort, tips, telephone, status,version, createuser, createtime,parent,step,org_range,inactive,address,zipcode,leader,fax,email,synchronization_time,del_flag,erp_orgname,depttype) "
            + "values (#{pid}, #{code},#{pcode}, #{simplename}, #{fullname}, #{type}, #{sort}, #{tips}, #{telephone}, #{status}, #{version}, #{createuser}, #{createtime}, #{parent}, #{step}, #{org_range}, #{inactive}, #{address}, #{zipcode}, #{leader}, #{fax}, #{email}, #{synchronization_time}, '0',#{erp_orgname},#{depttype})"})
    int deptSave(SysDept dept);

    @Select("select id, pid, code, pcode,simplename, fullname, type, sort, tips, telephone, status,version,createuser, updateuser, createtime, updatetime,parent,step,org_range,inactive,address,zipcode,leader,fax,email,synchronization_time,del_flag,erp_orgname,depttype from sys_dept t where t.del_flag='0' and t.code = #{code} limit 1")
    Map<String,Object> findByDeptCode(String code);

    @Select("select p.parameter,p.isRequired,p.parameterType,p.maxLength,p.diftype from bl_parametersrecord p where p.diftype='request' and p.maincode = #{id}")
    List<Map<String,Object>> findVisit(Integer id);

    @Select("select id from bl_interfacerecord where requesturl = #{requesturl}")
    Integer findByUrl(String url);

    @Insert("insert into biz_flow_countersign(app,biz_id,node_id,countersign) values(#{app},#{bizId},#{nodeId},#{countersign})")
    void insertCountersign(BizFlowCountersign bizFlowCountersign);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into biz_flow_consult_cfg(app,biz_id,node_id,isConsulted,consultUserIds,consultUsers,isTimed,timeDuration,consultDesc,oldExecutors,createUser) values(#{app},#{bizId},#{nodeId},#{isConsulted},#{consultUserIds},#{consultUsers},#{isTimed},#{timeDuration},#{consultDesc},#{oldExecutors},#{createUser})")
    int insertConsult(BizFlowConsult bizFlowConsult);

    @Insert("insert into biz_flow_consult_dtl(consultId,consultUserId,consultUser,status) values(#{consultId},#{consultUserId},#{consultUser},#{status})")
    void insertConsultDtl(BizFlowConsultDtl bizFlowConsultDtl);

    @Select("select type from act_cus_candidate " +
            "where proc_def_id = (select proc_def_id from biz_flow_app where app = #{app} and biz_id = #{bizId}) " +
            "and node_id = #{nodeId}")
    String getAgentType(String app, Long bizId, String nodeId);

    @Select("select proc_ins_id from biz_flow_app where app = #{app} and biz_id = #{bizId}")
    String getProcInsId(String app, Long bizId);
}
